#include "../inc/face.h"
#include "../inc/lcd.h"
#include "../inc/bmp.h"
#include "./../inc/touch.h"
#include "../inc/showfont.h"
#include "point.h"
#include "touch.h"
#include <iostream>
using namespace std;

Face::Face() : current_state(FaceState::HOME_SCREEN)
{
}

Face::~Face()
{
}

void Face::show_home_screen()
{
    Lcd *lcd = Lcd::instance();

    // 显示首页背景图片
    BMP home_bg("./res/home_bg.bmp");
    home_bg.show(lcd->addr());

    current_state = FaceState::HOME_SCREEN;
}
void Face::show_game_over_screen()
{
    Lcd *lcd = Lcd::instance();

    // 显示游戏结束背景图片
    BMP game_over_bg("./res/game_over.bmp");
    game_over_bg.show(lcd->addr());

    current_state = FaceState::GAME_OVER_SCREEN;
}
int Face::wait_for_start()
{
    Touch *touch = Touch::instance();
    Point p(0, 0);
    touch->wait(p);
    int x = p.x();
    int y = p.y();

    // 进入单人模式
    if (FaceState::HOME_SCREEN == current_state)
    {
          if (x > 170 && x < 400)
        {
            if (y > 160 && y < 325)
            {
                return 1;
            }
        }
        if (x > 410 && x < 625)
        {
            if (y > 160 && y < 325)
            {    
                return 2;
            }
        }
    }
    else if (FaceState::GAME_OVER_SCREEN == current_state)
    {
        // 游戏结束，重新开始
        if (x > 170 && x < 400)
        {
            if (y > 160 && y < 325)
            {
                return 2;
            }
        }
        else if (x > 410 && x < 625)
        {
            if (y > 160 && y < 325)
            {
                current_state = FaceState::HOME_SCREEN;
                return 3;
            }
        }
    }

    return 0;
}

FaceState Face::get_current_state() const
{
    return current_state;
}

void Face::set_current_state(FaceState state)
{
    current_state = state;
}

// 测试文本框位置
void Face::showText()
{
    // 获取ShowFont实例
    ShowFont *showFont = ShowFont::instance();

    showFont->display(
        (char *)"text.c_str",
        32,
        100,
        50,
        ShowFont::yellow,
        ShowFont::black,
        330,
        150);
}